package com.mt.mtyx.common.utils.generate.generate.config;

import javax.swing.filechooser.FileSystemView;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
 * @author WMT
 * @Date 2023/5/26 17:27
 */
public class GlobalCodeConfig {

    /**
     * 是否开启swagger注解
     */
    private boolean enableSwagger;

    /**
     * 是否开启mybatis
     */
    private boolean mybatis;

    /**
     * 注释 作者名称
     */
    private String author;

    /**
     * 注释 日期格式
     */
    private String format = "yyyy-MM-dd";

    /**
     * 输出目录
     */
    private String outDir = FileSystemView.getFileSystemView().getHomeDirectory().toString();

    /**
     * 是否打开输出目录文件
     */
    private boolean openOutDir;

    /**
     * 是否覆盖源文件
     */
    private boolean openOverride;

    /**
     * 是否自动生成增删改查方法
     */
    private boolean enableGenerateDll;

    /**
     * 分页对象
     */
    private String jsonPageCLass;

    /**
     * 文件生成配置
     */
    private static final Map<String,Boolean> generateConfig;

    static {
        generateConfig = new HashMap<>();
        generateConfig.put("entity",true);
        generateConfig.put("mapper",true);
        generateConfig.put("xml",true);
        generateConfig.put("service",true);
        generateConfig.put("serviceImpl",true);
        generateConfig.put("controller",true);
        generateConfig.put("other",true);
    }

    public boolean isEnableGenerateDll() {
        return enableGenerateDll;
    }

    public GlobalCodeConfig enableGenerateDll(boolean enableGenerateDll) {
        this.enableGenerateDll = enableGenerateDll;
        return this;
    }

    public boolean isEnableSwagger() {
        return enableSwagger;
    }

    public GlobalCodeConfig enableSwagger(boolean enableSwagger) {
        this.enableSwagger = enableSwagger;
        return this;
    }

    public String getAuthor() {
        return author;
    }

    public GlobalCodeConfig author(String author) {
        this.author = author;
        return this;
    }

    public boolean isMybatis() {
        return mybatis;
    }

    public GlobalCodeConfig mybatis(boolean mybatis) {
        this.mybatis = mybatis;
        return this;
    }

    public String getFormat() {
        return format;
    }

    public GlobalCodeConfig format(String format) {
        this.format = format;
        return this;
    }

    public String getOutDir() {
        return outDir;
    }

    public GlobalCodeConfig outDir(String outDir) {
        this.outDir = outDir;
        return this;
    }

    public boolean isOpenOutDir() {
        return openOutDir;
    }

    public Map<String, Boolean> getGenerateConfig() {
        return generateConfig;
    }

    public GlobalCodeConfig openOutDir(boolean openOutDir) {
        this.openOutDir = openOutDir;
        return this;
    }

    public boolean isOpenOverride() {
        return openOverride;
    }

    public GlobalCodeConfig openOverride(boolean openOverride) {
        this.openOverride = openOverride;
        return this;
    }

    public String getJsonPageCLass() {
        return jsonPageCLass;
    }

    public GlobalCodeConfig jsonPageCLass(String jsonPageCLass) {
        this.jsonPageCLass = jsonPageCLass;
        return this;
    }

    public GlobalCodeConfig jsonPageCLass(Class<?> clazz) {
        this.jsonPageCLass = clazz.getName();
        return this;
    }

    public GlobalCodeConfig generateConfig(Consumer<Map<String,Boolean>> generate){
        generate.accept(generateConfig);
        return this;
    }


}
